/****************************************************************************
 *   <SPG2 - Secure Password Generator>
 *   Copyright (C) 2010  <Robert Carr>
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 *   @author Robert Carr (etftw)
 *   @version 2.5.4
 *   
 ***************************************************************************/

package spg2;

import java.awt.Cursor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class MainMenu extends JFrame implements ActionListener
{
	private static final long serialVersionUID = 7291202540236621013L;
	private static boolean instantiated;
	private ImagePanel imgLogo;
	private ImagePanel imgBank;
	private ImagePanel imgGenerator;
	
	public static void setInstantiated(boolean instantiated) 
	{
		MainMenu.instantiated = instantiated;
	}

	public static boolean isInstantiated() 
	{
		return instantiated;
	}
	
	public MainMenu(String title) throws Exception
	{
		super(title);
		if(MainMenu.isInstantiated())
		{
			throw new Exception("Class already instantiated");
		}
		else
		{
			setupUI();			
			MainMenu.setInstantiated(true);
		}
	}
	
	private void setupUI()
	{
		// Initialize and setup the JFrame
        setSize(412, 390);
        setResizable(false);
        getContentPane().setLayout(null);
        int x = ((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2) - 206;
        int y = ((int)Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2) - 195;
        setLocation(x, y);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        // Initialize the logo
        imgLogo = new ImagePanel(new ImageIcon(SPG2.class.getResource("logo.png")).getImage());
        imgLogo.setLocation(20, 10);
        imgLogo.setVisible(true);
        
        // Initialize the buttons
        imgBank = new ImagePanel(new ImageIcon(SPG2.class.getResource("password_bank.png")).getImage());
        imgBank.setLocation(10, 120);
        imgBank.setCursor(new Cursor(Cursor.HAND_CURSOR));
        imgBank.addMouseListener(new MouseListener()
        {
			@Override
			public void mouseEntered(MouseEvent arg0) {
				imgBank.setImage(new ImageIcon(SPG2.class.getResource("password_bank_hover.png")).getImage());
				imgBank.setVisible(false);
				imgBank.setVisible(true);
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				imgBank.setImage(new ImageIcon(SPG2.class.getResource("password_bank.png")).getImage());
				imgBank.setVisible(false);
				imgBank.setVisible(true);
			}

			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
        });
        imgBank.setVisible(true);
        
        imgGenerator = new ImagePanel(new ImageIcon(SPG2.class.getResource("generator.png")).getImage());
        imgGenerator.setLocation(10, 240);
        imgGenerator.setCursor(new Cursor(Cursor.HAND_CURSOR));
        imgGenerator.addMouseListener(new MouseListener()
        {
			@Override
			public void mouseEntered(MouseEvent arg0) {
				imgGenerator.setImage(new ImageIcon(SPG2.class.getResource("generator_hover.png")).getImage());
				imgGenerator.setVisible(false);
				imgGenerator.setVisible(true);
			}

			@Override
			public void mouseExited(MouseEvent arg0) {
				imgGenerator.setImage(new ImageIcon(SPG2.class.getResource("generator.png")).getImage());
				imgGenerator.setVisible(false);
				imgGenerator.setVisible(true);
			}

			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
        });
        imgGenerator.setVisible(true);
        
        getContentPane().add(imgLogo);
        getContentPane().add(imgBank);
        getContentPane().add(imgGenerator);
        setVisible(true);
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) 
	{
	}
}
